import Vue from "vue";
import VueRouter from "vue-router";
import agents from "./module/agents";
import categories from "./module/categories";
import czyc from "./module/czyc";
import home from "./module/home";
import lxwm from "./module/lxwm";
import news from "./module/news";
Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    agents,
    czyc,
    home,
    lxwm,
    news,
    categories,
    {
      path: "/test",
      component: () => import("@/views/test"),
      meta:{title:'测试'}
    },
    {
      path: "/",
      redirect: "/home",
    },
    {
      path: "/404",
      component: () => import("@/views/404"),
      meta: { isShow: true,title:'404' },
    },
    {
      path: "*",
      redirect: "/404",
    },
  ],
});

// 全局后置守卫：初始化时、每次路由切换后执行
router.afterEach((to, from) => {
  console.log("afterEach", to, from);
  if (to.meta.title) {
    document.title = to.meta.title; //修改网页的title
  } else {
    document.title = "vue_test";
  }
});

export default router;
